//
//  RegisterServiceViewController.m
//  UESTCPioneer
//
//  Created by Apple on 14-6-17.
//  Copyright (c) 2014年 Sway. All rights reserved.
//

#import "RegisterServiceViewController.h"

@interface RegisterServiceViewController ()
{
    agreeBlock _agreeBlock;
}
@property (nonatomic,strong) UITextView * contentView;
@end

@implementation RegisterServiceViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (id) initWithContent:(NSString*)content agreeBlock:(agreeBlock)block{
    if (self) {
        _agreeBlock = block;
        self.content = content;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"注册协议";
    
    
    CGRect rect = CGRectMake(0, 15, self.view.frame.size.width, self.view.frame.size.height - 80);
    _contentView = [[UITextView alloc] initWithFrame:rect];
//    [_contentView setBackgroundColor:[UIColor redColor]];
    _contentView.editable = NO;
    _contentView.text = self.content;
    _contentView.font = [UIFont systemFontOfSize:14.0];
    _contentView.textColor = [UIColor colorWithRed:100.0/255.0 green:100.0/255.0 blue:100.0/255.0 alpha:1];
    [self.view addSubview:_contentView];
    
    UIButton * sureButton = [[UIButton alloc] initWithFrame:CGRectMake(20, _contentView.frame.size.height + 30,(_contentView.frame.size.width-60)/2 , 30)];
    [self.view addSubview:sureButton];
    [sureButton setTitle:@"我同意" forState:UIControlStateNormal];
    [sureButton setBackgroundColor:kNavigationBarColor];
    [sureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [sureButton.layer setCornerRadius:5];
    [sureButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [sureButton setHighlighted:YES];
    [sureButton addTarget:self action:@selector(sureButton:) forControlEvents:UIControlEventTouchUpInside];
    UIButton * cancelButton = [[UIButton alloc] initWithFrame:CGRectMake(40+sureButton.frame.size.width, _contentView.frame.size.height + 30,(_contentView.frame.size.width-60)/2 ,30)];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [self.view addSubview:cancelButton];
    [cancelButton setBackgroundColor:kNavigationBarColor];
    [cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cancelButton.layer setCornerRadius:5];
    [cancelButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [cancelButton setHighlighted:YES];
    [cancelButton addTarget:self action:@selector(cancelButton:) forControlEvents:UIControlEventTouchUpInside];
//    [_contentView setTranslatesAutoresizingMaskIntoConstraints:NO];
//    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_contentView
//                                                          attribute:NSLayoutAttributeTop
//                                                          relatedBy:NSLayoutRelationEqual
//                                                             toItem:self.view
//                                                          attribute:NSLayoutAttributeTop
//                                                         multiplier:1 constant:0]];
//    
//    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_contentView
//                                                          attribute:NSLayoutAttributeLeft
//                                                          relatedBy:NSLayoutRelationEqual
//                                                             toItem:self.view
//                                                          attribute:NSLayoutAttributeLeft
//                                                         multiplier:1 constant:0]];
//    
//    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_contentView
//                                                          attribute:NSLayoutAttributeRight
//                                                          relatedBy:NSLayoutRelationEqual
//                                                             toItem:self.view
//                                                          attribute:NSLayoutAttributeRight
//                                                         multiplier:1 constant:0]];
//    
   
//    UIButton * sureButton = [[UIButton alloc] init];
//    [self.view addSubview:sureButton];
//    [sureButton setTranslatesAutoresizingMaskIntoConstraints:NO];
//    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:sureButton
//                                                          attribute:NSLayoutAttributeTop
//                                                          relatedBy:NSLayoutRelationEqual
//                                                             toItem:_contentView
//                                                          attribute:NSLayoutAttributeBottom
//                                                         multiplier:1 constant:12]];
//    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:sureButton
//                                                          attribute:NSLayoutAttributeLeft
//                                                          relatedBy:NSLayoutRelationEqual
//                                                             toItem:_contentView
//                                                          attribute:NSLayoutAttributeLeft
//                                                         multiplier:1 constant:12]];
//    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[sureButton(==70)]" options:0 metrics:Nil views:NSDictionaryOfVariableBindings(sureButton)]];
//    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[sureButton(==21)]" options:0 metrics:Nil views:NSDictionaryOfVariableBindings(sureButton)]];
//    
//    UIButton * cancelButton = [[UIButton alloc] init];
//    [self.view addSubview:cancelButton];
//    [cancelButton setTranslatesAutoresizingMaskIntoConstraints:NO];
//    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:cancelButton
//                                                          attribute:NSLayoutAttributeTop
//                                                          relatedBy:NSLayoutRelationEqual
//                                                             toItem:_contentView
//                                                          attribute:NSLayoutAttributeBottom
//                                                         multiplier:1 constant:12]];
//    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:sureButton
//                                                          attribute:NSLayoutAttributeRight
//                                                          relatedBy:NSLayoutRelationEqual
//                                                             toItem:_contentView
//                                                          attribute:NSLayoutAttributeRight
//                                                         multiplier:1 constant:12]];
//    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[cancelButton(==70)]" options:0 metrics:Nil views:NSDictionaryOfVariableBindings(cancelButton)]];
//    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[cancelButton(==21)]" options:0 metrics:Nil views:NSDictionaryOfVariableBindings(cancelButton)]];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)sureButton:(UIButton *)btn{
    _agreeBlock();
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)cancelButton:(UIButton *)btn{
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
